Add custom method to string object [closed]

Posted by cru3l on Stack Overflow See other posts from Stack Overflow or by cru3l
Published on 2011-01-15T10:53:20Z Indexed on 2011/01/15 13:53 UTC
Read the original article Hit count: 187

Filed under:
|
|

Possible Duplicate:
Can I add custom methods/attributes to built-in Python types?

In Ruby you can override any built-in object class with custom method, like this:

class String
  def sayHello
    return self+" is saying hello!"
  end
end                              

puts 'JOHN'.downcase.sayHello   # >>> 'john is saying hello!'

How can i do that in python? Is there a normally way or just hacks?

© Stack Overflow or respective owner

Related posts about python

Related posts about ruby